package cn.com.freelibra.forum.util;

import java.security.MessageDigest;

public class MD5Util {
	public static String MD5(String inStr) {
		MessageDigest md5 = null;

		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (Exception arg7) {
			System.out.println(arg7.toString());
			arg7.printStackTrace();
			return "";
		}

		char[] charArray = inStr.toCharArray();
		byte[] byteArray = new byte[charArray.length];

		for (int md5Bytes = 0; md5Bytes < charArray.length; ++md5Bytes) {
			byteArray[md5Bytes] = (byte) charArray[md5Bytes];
		}

		byte[] arg8 = md5.digest(byteArray);
		StringBuffer hexValue = new StringBuffer();

		for (int i = 0; i < arg8.length; ++i) {
			int val = arg8[i] & 255;
			if (val < 16) {
				hexValue.append("0");
			}

			hexValue.append(Integer.toHexString(val));
		}

		return hexValue.toString();
	}
}